// pages/index/inputInfo.js
const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fpdm: '',
    fphm: '',
    kprq: '',
    ext: '',
    extName: '不含税金额',
    extInputType: 'digit',
    hiddenLoading: true,
    // codes:[
    //   '144031539110',
    //   '131001570151',
    //   '133011501118',
    //   '111001571071'
    // ]
  },
  bindInput: function(e) {
    var id = e.target.id
    this.setData({
      [id]: e.detail.value
    })
  },
  bindblur: function(e) {
    var fpdm = e.detail.value
    var invoicetype = util.getInvoiceType(fpdm)
    var extName
    var extInputType
    if (invoicetype == '01') {
      extName = '不含税金额'
      extInputType = 'digit'
    } else {
      extName = '校验码后6位'
      extInputType = 'number'
    }

    this.setData({
      extName: extName,
      extInputType: extInputType
    })
  },
  bindConfirm: function(e) {
    var that = this
    that.setData({
      hiddenLoading: false,
    })
    var yzmurl = 'https://wx.fapiaohelp.com/verify-service/invoice/check?'
    yzmurl = yzmurl + 'fpdm=' + that.data.fpdm + '&fphm=' + that.data.fphm + '&kprq=' + that.data.kprq + '&ext=' + that.data.ext
    console.log(yzmurl)
    wx.request({
      url: yzmurl,
      success: function(res) {
        console.log(res.data)
        if (res.data["returnCode"] < 0) {
          wx.showModal({
            title: '错误',
            content: res.data["errorMessage"],
            showCancel: false,
            complete: function() {
              console.log("错误：" + res.data["errorMessage"])
            }
          })
        } else {
          wx.setStorage({
            key: 'detail',
            data: res.data,
            success: function(res) {
              wx.navigateTo({
                url: 'code?detail=' + res.data,
              })
            }
          })
        }
      },
      complete: function(res) {
        that.setData({
          hiddenLoading: true,
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})